package LCR_code;

import java.util.HashMap;

/**
 * @author blh
 * @date 2024年08月11日 16:20
 */
public class LCR_154_811 {
    public Node copyRandomList(Node head) {
        HashMap<Node, Node> hashMap = new HashMap<>();
        Node tempNode = head;
        while (tempNode != null) {
            hashMap.put(tempNode, new Node(tempNode.val));
            tempNode = tempNode.next;
        }
        tempNode = head;
        while (tempNode != null) {
            Node temp = hashMap.get(tempNode);
            temp.random = hashMap.get(tempNode.random);
            temp.next = hashMap.get(tempNode.next);
            tempNode = tempNode.next;
        }
        return hashMap.get(head);
    }
}
